package twitter.client.listener;

import org.apache.commons.lang3.StringUtils;

import twitter.client.R;
import twitter.client.util.Consts;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class TweetTextOnEditorActionListener implements OnEditorActionListener {

	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		String text = v.getText().toString();

		Button tweetButton = (Button) v.getRootView().findViewById(
				R.id.tweetExecButton);
		TextView textLength = (TextView) v.getRootView().findViewById(
				R.id.tweetPostTextLength);
		textLength.setText(String.valueOf(Consts.TWITTER_MAX_LENGTH
				- text.length()));

		if (StringUtils.isNotEmpty(text)) {
			tweetButton.setEnabled(true);
		} else {
			tweetButton.setEnabled(false);
		}

		return true;
	}
}
